<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //创建一个父级
        function Parent(name,age) {
            //添加实例方法
            this.name = name
            this.age = age
        }
        //添加原型方法
        Parent.prototype.eat = function() {
            console.log("吃遍大江南北");
        }
        
        //创建子级
        function Child(name,age,hobby) {
            //将子级的this指向父级
            Parent.call(this,name,age)
            this.hobby = hobby
        }

        //添加子类原型方法
        Child.prototype.play =  function(){
            console.log("玩遍大江南北");
        }

        Child.myChild = function(){
            console.log("这是父类自己的方法");
        }

        //让子类的原型指向父类的原型对象
        Child.prototype = new Parent
        //修正子类原型对象的constructor指向
        Child.prototype.constructor = Child

        const c1 = new Child("张三","18","吃喝玩乐")
        console.log(c1);

        const c2 = new Parent()
        console.log(c2);


    </script>
</body>
</html>